﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "PumpService" in code, svc and config file together.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class PumpService : IPumpService
{
    private readonly StationGateway _gateway;
    private readonly WaterLevelLogGateWay _log;

    public PumpService()
    {
        _gateway = new StationGateway();
        _log = new WaterLevelLogGateWay();
    }

    public bool AddStation(string ipAdress, int port, double waterLevel, int status)
    {
        return _gateway.AddStation(ipAdress, port, waterLevel, status);
    }

    public bool AddPump(double capacity, int status, int stationId)
    {
        return _gateway.AddPump(capacity, status, stationId);
    }

    public bool EditStation(int id, string ipAdress, int port, double waterLevel, int status)
    {
        return _gateway.EditStation(id, ipAdress, port, waterLevel, status);
    }

    public bool EditPump(double capacity, int status, int pumpId)
    {
        return _gateway.EditPump(capacity, status, pumpId);
    }

    public bool RemovePump(int id)
    {
        return _gateway.RemovePump(id);
    }

    // Remove pumps by station id:
    public bool RemovePumpsByStationId(int stationId)
    {
        return _gateway.RemovePumpsByStationId(stationId);
    }

    public bool RemoveStation(int id)
    {
        return _gateway.RemoveStation(id);
    }

    public List<Pump> RequestCurrentStatus(int stationId)
    {
        return _gateway.GetPump(stationId);
    }

    public bool StartStation(int id)
    {
        return _gateway.StartStation(id);
    }

    public bool StartPump(int id)
    {
        return _gateway.StartPump(id);
    }

    public bool StopStation(int id)
    {
        return _gateway.StopStation(id);
    }

    public bool StopPump(int id)
    {
        return _gateway.StopPump(id);
    }

    public List<Station> RequestCurrentStatusForAll()
    {
        return _gateway.RequestInfoForStations();
    }

    public Station FindStation(int stationId)
    {
        return _gateway.FindStation(stationId);
    }

    public Pump FindPump(int pumpId)
    {
        return _gateway.FindPump(pumpId);
    }

    #region Log
    public bool AddLog(int stationId, double waterIn, double waterLevel, DateTime date)
    {   
        return _log.Add(stationId, waterIn, 0, waterLevel, date); //waterout is default 0
    }

    public bool UpdateLog(int stationId, double waterOut, double waterLevel, DateTime date)
    {
        return _log.Edit(stationId, date, waterOut, waterLevel);
    }    
    public List<WaterLevelLog> RequestLog(Station station)
    {
        return new List<WaterLevelLog>();
    }

    #endregion
}